<template>
    <div class='page-login df aic jcc'>
      <div class="form">
        <div class="logo-box df jcc aic">
          <img class="logo" src="../../assets/imgs/2.png" alt="">
          后院食舍外卖系统
        </div>
        <el-form  :model="formData" :rules='rules' ref="formRef">
          <el-form-item prop="account">
            <el-input prefix-icon='iconfont icon-24gf-userGroup2' v-model="formData.account"></el-input>
          </el-form-item>
          <!-- 密码 -->
          <el-form-item prop="password">
            <el-input type="flag ? 'text' : 'password'"
            v-model="formData.password"
            @keyup.native.enter="submit">
              <!-- 插槽形式 -->
              <i slot="prefix" class="iconfont icon-taocan-suoxiao"></i>
              <i slot="suffix" @click="flag = !flag" class="iconfont" :class="flag ? 'icon-yanjing' : 'icon-biyan--'"></i>
            </el-input>
          </el-form-item>
          <!-- 登录按钮 -->
          <el-form-item>
          <el-button @click="submit" type="primary" class="btn">登录</el-button>
        </el-form-item>
        </el-form>
      </div>
    </div>
  </template>
<script>
//解构vuex辅助函数
import {mapActions} from 'vuex'
export default {
  data() {
    return {
      //节流loading
      loading: false,
      //表单数据
      formData: {
        account: '',
        password: '',
      },
      //眼睛
      flag: false,
      rules: {
        account: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
          {min: 3, max: 12, message: '长度在 3 到 12 个字符', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 6, max: 12, message: '长度在 6 到 12 个字符', trigger: 'blur'},
        ],
      },
    }
  },
  methods: {
    ...mapActions('user', ['A_login']),
    //登录操作
    submit() {
      this.$refs.formRef.validate(async valid => {
        //判断
        if (valid) {
          //发送请求 等待Promise状态切换完成 执行后面代码
          await this.A_login(this.formData)

          //跳转操作
          this.$router.push('/home')
        } else {
          console.log('验证失败')
        }
      })
    },
  },
}
</script>
  
  <style lang="scss" scoped>
  .page-login {
    height: 100%;
    background: url("../../assets/imgs/food7.jpg") top center no-repeat;
    background-size: auto 140%;
  
    .form {
      width: 400px;
      height: 300px;
      // background: darkcyan;
    }
  }
  
  .btn-submit {
    width: 100%;
  }
  
  .logo-box {
    width: 100%;
    font-size: 20px;
    margin-bottom: 10px;
    color: rgb(255, 255, 255);
    font-weight: bold;
    //   font-family: '宋体';
  }
  
  .logo {
    width: 55px;
    -webkit-animation: slide-in-fwd-center 3s linear;
    margin-right: 5px;
  }
  ::v-deep .el-input__inner {
    background: transparent;
    color: white;
   
  }
  ::v-deep .el-input__prefix{
    line-height: 36px;
  }
  ::v-deep.icon-biyan--{
    line-height: 36px;
  }
  ::v-deep.icon-yanjing{
    line-height: 36px;
  }
 
  
  @-webkit-keyframes slide-in-fwd-center {
    0% {
      -webkit-transform: translateZ(-1400px);
      transform: translateZ(-1400px);
      opacity: 0;
    }
  
    100% {
      -webkit-transform: translateZ(0);
      transform: translateZ(0);
      opacity: 1;
    }
  }
  
  @keyframes slide-in-fwd-center {
    0% {
      -webkit-transform: translateZ(-1400px);
      transform: translateZ(-1400px);
      opacity: 0;
    }
  
    100% {
      -webkit-transform: translateZ(0);
      transform: translateZ(0);
      opacity: 1;
    }
  }
  </style>